# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# Old AUR contributors / lame backdoorers:
# Old Maintainer: Brian Bidulock <bidulock@openss7.org>
# Old Contributo: Jianhui Z <jianhui@outlook.com>
# Old Contributo: Tau Tsao <realturner at gmail.com>
# Old Contributor: Tomasz Zok <tomasz.zok [at] gmail.com>
# Old Contributor: techryda <techryda at silentdome dot com>
# Old Contributor: Mathias R. <pu154r@overlinux.org>
# Old Contributor: Alan Beale <the.mrabz@gmail.com>

pkgname=xrdp
pkgver=0.10.4.1
pkgrel=1
pkgdesc='An open source remote desktop protocol (RDP) server.'
url='https://github.com/neutrinolabs/xrdp'
arch=('x86_64' 'aarch64')
license=('Apache-2.0')
depends=('libxrandr' 'libfdk-aac' 'ffmpeg' 'imlib2' 'fuse3' 'x264')
makedepends=('nasm' 'cmocka')
checkdepends=('check')
optdepends=('tigervnc' 'tightvnc' 'realvnc-vnc-server')
backup=('etc/xrdp/sesman.ini'
    'etc/xrdp/xrdp.ini'
    'etc/xrdp/cert.pem'
    'etc/xrdp/key.pem'
    'etc/xrdp/startwm.sh'
    'etc/xrdp/reconnectwm.sh'
    'etc/default/xrdp')
install="$pkgname.install"
source=("https://github.com/neutrinolabs/xrdp/releases/download/v$pkgver/xrdp-$pkgver.tar.gz"
        'arch-config.diff')
sha512sums=('7a34a16a613c313045d42b9fec038babc363ebdf82f8acde6146aa2ad68e2145e74e674f368afa1629e1408e009d74393689711a52b8d490c70b050ec8962f69'
            '50cb23c8267a2de7d7708875e5133787651e55208f819f8b87beb71cbbbb956511dac9f52e0240d0d0e27a5b7f76b1a132832dd471f54d5aa09b3a0f0b845e4e')

prepare() {
  cd "$pkgname-$pkgver"

  patch -Np2 -b -z .orig <../arch-config.diff
  ./bootstrap
}

build() {
  cd "$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --with-systemdsystemunitdir=/usr/lib/systemd/system \
    --enable-jpeg \
    --enable-tjpeg \
    --enable-fuse \
	  --enable-fdkaac \
	  --enable-opus \
	  --enable-rfxcodec \
	  --enable-mp3lame \
	  --enable-pixman \
	  --enable-painter \
	  --enable-vsock \
	  --enable-ipv6 \
	  --enable-pam-config=arch \
	  --enable-rdpsndaudin \
	  --with-imlib2 \
	  --enable-x264

  # Fight unused direct deps
  sed -i -e "s| -shared | $LDFLAGS\0 |g" -e "s|    if test \"\$export_dynamic\" = yes && test -n \"\$export_dynamic_flag_spec\"; then|      func_append compile_command \" $LDFLAGS\"\n      func_append finalize_command \" $LDFLAGS\"\n\0|" libtool

  make
}

package() {
  cd "$pkgname-$pkgver"

  sed -i 's^param=Xorg^param=/usr/lib/Xorg^g' sesman/sesman.ini
  make DESTDIR="$pkgdir" install
  rm -f "$pkgdir"/etc/xrdp/rsakeys.ini
  install -Dm644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING
  install -Dm644 instfiles/default/xrdp "$pkgdir"/etc/default/xrdp
}

